package com.liu.controller;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
import com.liu.R;
import com.liu.service.VideoService;
import com.liu.video.InitClient;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.ws.rs.Path;
import java.io.IOException;
import java.util.List;

/**
 * **************
 * 项目名称: testgulili <br/>
 * 文件名称:  <br/>
 * 文件描述: 这里添加您的类文件描述，说明当前文件要包含的功能。 <br/>
 * 文件创建：刘世锦 <br/>
 * 创建时间: 2021/12/28 <br/>
 *
 * @version v1.0 <br/>
 * @update [序号][日期YYYY-MM-DD][更改人姓名][变更描述]<br/>
 * *************
 */
@RestController
@CrossOrigin
@RequestMapping("/Video/file")
public class VideoController {

    @Autowired
    private VideoService service;

//    上传文件
    @ApiOperation(value = "文件上传")
    @PostMapping("/uploadVideo")
    public R upload(MultipartFile file) throws IOException {

            String VideoSourceId  =     service.uploadVideo(file);

     if (VideoSourceId==null){
         return R.ok().message("视频上传失败").data("VideoSourceId",VideoSourceId);

     }else {
         return R.ok().message("视频上传成功").data("VideoSourceId",VideoSourceId);

     }
   }

    // 删除阿里视频 根据videoID
    @DeleteMapping("/Deletevideo/{VideoSourceId}")
    public  R deleteVideo(@PathVariable String VideoSourceId) {
        if (ObjectUtils.isNotEmpty(VideoSourceId)) {
            service.deleteVideo(VideoSourceId);

            return R.ok();
        }
        return R.ok().message("VideoSourceId是空");
    }
    @DeleteMapping("/DeleteseveralVideo")
    public R DeleteseveralVideo(@RequestParam("VideoList") List<String> VideoList){
        service.DeleteseveralVideo(VideoList);
        return R.ok().message("多个视频删除成功");


    }


    @GetMapping("/getPlayAuth/{VideoSourceId}")
    public R getPlayAuth(@PathVariable String VideoSourceId) throws ClientException {

      String   playAUth=   service.getVideoPlayAuth(VideoSourceId);

        return R.ok().message("获取凭证成功").data("playAuth",playAUth);
    }
}
